#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int cnt = n/2;
	int ans = cnt;
	if(n%2) ans++;
	for(int i = 0;i<cnt;i++)
	{
		if(ans%m==0)
		{
			cout<<ans<<endl;
			return 0;
		}
		else ans++;
	}
	if(ans%m==0) cout<<ans<<endl;
	else cout<<"-1"<<endl;
	return 0;
}
